master @ 49 LINES
[ HISTORY ] [ UP ]
┌─ ASTRO ────────────────────────────────────────────────────────────────────┐
│ --- │
│ import PlayerProfileLayout from "../../layouts/PlayerProfileLayout.astro"; │
│ import { fetchPlayerProfile } from "../../lib/api"; │
│ import type { PlayerProfileData } from "../../lib/types"; │
│ │
│ export const prerender = false; │
│ │
│ const slug = Astro.params.slug || ""; │
│ const slugParts = slug.split("/").filter(Boolean); │
│ │
│ const region = slugParts[0] || ""; │
│ const realmSlug = slugParts[1] || ""; │
│ const playerName = slugParts[2] || ""; │
│ // Season is the optional 4th segment: "season{N}" or "all-time". When absent │
│ // the layout defaults to the latest season the player has data for. │
│ const seasonSlug = slugParts[3] || ""; │
│ let requestedSeason: string | null = null; │
│ const seasonMatch = seasonSlug.match(/^season(\d+)$/); │
│ if (seasonMatch) requestedSeason = seasonMatch[1]; │
│ else if (seasonSlug === "all-time") requestedSeason = "all-time"; │
│ │
│ let playerData: PlayerProfileData | null = null; │
│ let error: string | null = null; │
│ │
│ if (region && realmSlug && playerName) { │
│ try { │
│ const origin = Astro.url?.origin || Astro.site || ""; │
│ playerData = await fetchPlayerProfile( │
│ region, │
│ realmSlug, │
│ playerName, │
│ origin, │
│ ); │
│ } catch (err: any) { │
│ console.error("[PlayerPage] Error fetching player data:", err); │
│ error = err.message || "Failed to load player data"; │
│ } │
│ } │
│ --- │
│ │
│ <PlayerProfileLayout │
│ region={region} │
│ realmSlug={realmSlug} │
│ playerName={playerName} │
│ playerData={playerData} │
│ requestedSeason={requestedSeason} │
│ error={error} │
│ /> │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ ASTRO ──────────────────────────────┐
│ --- │
│ import PlayerProfileLayout from "../../layou │
│ ts/PlayerProfileLayout.astro"; │
│ import { fetchPlayerProfile } from "../../li │
│ b/api"; │
│ import type { PlayerProfileData } from "../. │
│ ./lib/types"; │
│ │
│ export const prerender = false; │
│ │
│ const slug = Astro.params.slug || ""; │
│ const slugParts = slug.split("/").filter(Boo │
│ lean); │
│ │
│ const region = slugParts[0] || ""; │
│ const realmSlug = slugParts[1] || ""; │
│ const playerName = slugParts[2] || ""; │
│ // Season is the optional 4th segment: "seas │
│ on{N}" or "all-time". When absent │
│ // the layout defaults to the latest season │
│ the player has data for. │
│ const seasonSlug = slugParts[3] || ""; │
│ let requestedSeason: string | null = null; │
│ const seasonMatch = seasonSlug.match(/^seaso │
│ n(\d+)$/); │
│ if (seasonMatch) requestedSeason = seasonMat │
│ ch[1]; │
│ else if (seasonSlug === "all-time") requeste │
│ dSeason = "all-time"; │
│ │
│ let playerData: PlayerProfileData | null = n │
│ ull; │
│ let error: string | null = null; │
│ │
│ if (region && realmSlug && playerName) { │
│ try { │
│ const origin = Astro.url?.origin || Astr │
│ o.site || ""; │
│ playerData = await fetchPlayerProfile( │
│ region, │
│ realmSlug, │
│ playerName, │
│ origin, │
│ ); │
│ } catch (err: any) { │
│ console.error("[PlayerPage] Error fetchi │
│ ng player data:", err); │
│ error = err.message || "Failed to load p │
│ layer data"; │
│ } │
│ } │
│ --- │
│ │
│ <PlayerProfileLayout │
│ region={region} │
│ realmSlug={realmSlug} │
│ playerName={playerName} │
│ playerData={playerData} │
│ requestedSeason={requestedSeason} │
│ error={error} │
│ /> │
└──────────────────────────────────────────────┘
──────────────────────────────────────────────────────────────────────────────────────
OOKNET
────────────────────────────────────────────────
OOKNET